package com.ds.infrastructure.hyperspace.container.config;

import com.ds.infrastructure.hyperspace.monitor.config.MonitorConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.info.GitProperties;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

/**
 * @Author: yaozh
 * @Description: Add the commit ID of GIT code to Prometheus, so that you can know the version of the currently running code
 */
@Configuration
public class GitConfiguration {
    @Autowired(required = false)
    private GitProperties git;
    @Autowired
    private MonitorConfiguration monitorConfiguration;

    public String getShortCommitId() {
        if (git == null) {
            return "unknown";
        }
        return git.getShortCommitId();
    }

    @PostConstruct
    void init() {
        monitorConfiguration.getMetricsManager().gitShortCommitIdGauge(getShortCommitId());
    }
}
